//将数组作为方法的返回值，并将数组转置
package schoolDemo3;

public class App6_6{
    public static void main(String[] args) {
        //这里矩阵的形状必须是正方形，不然会发生数组指针越界的错误
        int[][] arr = {{1, 2, 3,4}, {5, 6, 7,8}, {9, 10, 11,12},{13,14,15,16}};
        Trans pose =new Trans();
        pose.tranSpose(arr);

        for(int i=0;i<arr.length;i++) {
            for (int j = 0; j < arr[i].length; j++)
                System.out.print(arr[i][j] + " ");
            System.out.println();
        }
    }
}
class Trans{
    int temp;
    int[][] tranSpose(int[][] array){
        for(int i=0;i<array.length;i++)
            for(int j=i+1;j<array[i].length;j++){
             temp=array[i][j];
             array[i][j]=array[j][i];
             array[j][i]=temp;
            }
        return array;
    }
}
